<?php
header("Content-type: text/html; charset=utf-8");
header("Access-Control-Allow-Origin: *");



//error_reporting(0);//取消一切错误警告。
// 连主库
$db = mysqli_connect(SAE_MYSQL_HOST_M . ':' . SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS);
if ($db) {
	mysqli_select_db($db, SAE_MYSQL_DB);
}
$arr = array();
$arr['Result'] = true;
$arr['Message'] = '';
$arr['CType'] = 0;
$contentArr = array();
$action = $_GET['action'];
$where = urldecode($_GET['where']);
$actionLength = strlen($action);
$table = strtolower(substr($action, 7, $actionLength - 11));
if ($action != null) {
	$respone;
	//从文件中读取jsonArray
	switch ($action) {
		case 'getFirstTabList':
            //将整个文件内容读入到一个字符串中
            	$file_path = "firsttab.txt";
	if(file_exists($file_path)){
	$str = file_get_contents($file_path);
	$str = str_replace("\r\n","<br />",$str);
    }
	}
	if ($str != null) {
		echo $str;
	} else {
		if (null != $where) {
			$sql = "SELECT * FROM `" . $table . "` WHERE " . $where . " LIMIT 0, 30 ";
		} else {
			switch ($action) {
				case 'getItemCommodityList':
                //$sql = "SELECT * FROM shopcart,commodity WHERE shopcart.shopCartId = commodity.belongToShopId";
                $sql = 'select * from shopcart as s
                 left join commodity c on s.shopCartId = c.belongToShopId
                 left join commoditysub cs on c. commodityId = cs.belongToCommodityId
                 where cs.countInCart > 0 ';
                break;
            default:
               $sql = "SELECT * FROM `".$table."` LIMIT 0, 30 ";
               break;
			}
	        }
	$result = mysqli_query($db, $sql);
	mysqli_data_seek($result, 0); //指针复位
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		//对每行记录进行运算 处理，如 ：echo $row['name']."<br />";
		$subArr = array();
		foreach ($row as $k => $v) {
			$subArr[$k] = $v;
		}
		array_push($contentArr, $subArr);
	}
	$arr['Content'] = $contentArr;
	$respone = json_encode($arr, JSON_UNESCAPED_UNICODE);
	echo $respone;
    }
}

//getItemChaoShiHuiList --> chaoshihui

//    $sql;
//   switch($action) {
//    case 'getItemGuessYouLikeList':
//    $sql = "SELECT * FROM `".$table."` ".$where."LIMIT 0, 30 ";
//    break;
//    case 'getItemChaoShiHuiList':
//  $sql = "SELECT * FROM `chaoshihui`  WHERE flag =  1 LIMIT 0, 30";
//    break;
//   }

//echo json_encode($respone);

////$url = 'http://app1.ycsd.cn/webSite/services/book.aspx?action=getchapterlist&userToken=&page=1&pageSize=30&total=0&date=&bid=2022';
//$url = 'http://app1.ycsd.cn/webSite/services/book.aspx?';
//foreach ($_REQUEST as $k=>$v) {
//    $url= $url.$k."=".$v."&";
//}
////print_r($url);//打印数组内容;或者使用var_dump()
//
//$html = file_get_contents($url);
////$html = iconv("UTF-8", "UTF-8,GBK,GB2312,BIG5", $html);
////$html = mb_convert_encoding($html, "UTF-8","GBK");
//$html = mb_convert_encoding($html, "UTF-8","UTF-8,GBK,GB2312,BIG5");
//echo $html;
?>